package fingerGussingGame2;

import java.util.Scanner;

public class Game
{
	Scanner scanner = new Scanner(System.in); // 系统输入
	Player pc; // 电脑
	Player user;// 用户
	int playTimes = 0;

	/**
	 * 开场动画
	 */
	public void initial()
	{
		System.out.println("===========================欢迎进入猜拳==========================" + "=========\n\n\n\n");
		System.out.println("                             ***************                    ");
		System.out.println("                             **  猜拳，开始**                          ");
		System.out.println("                             ***************                    \n\n\n\n\n\n");
		gameRules();
	}

	/**
	 * 游戏规则
	 */
	public void gameRules()
	{
		while (true)
		{
			System.out.println("游戏规则：1.石头 2.剪刀 3.布");
			System.out.println("请选择对手：1.刘备 2.曹操 3.孙权：");
			int role = scanner.nextInt();
			switch (role)
			{
			case 1:
				pc = new Computer("刘备");
				break;
			case 2:
				pc = new Computer("曹操");
				break;
			case 3:
				pc = new Computer("孙权");
				break;
			default:
				pc = new Computer("xx");
				break;
			}
			System.out.println("您选择了" + pc.getName() + "进行对战");
			// 用户名
			System.out.println("请输入你的名字");
			user = new People(scanner.next());
			System.out.println(user.getName() + "准备好猜拳了吗？（y/n）");
			if (scanner.next().toLowerCase().equals("y"))
			{
				break;
			}
		}
		startGame();
	}

	/**
	 * 进行游戏
	 */
	public void startGame()
	{
		while (true)
		{
			// 出拳
			switch (Option.isWon(user.showFirst(), pc.showFirst()))
			{
			case 0:
				System.out.println("平局");
				break;
			case 1:
				System.out.println("你赢了");
				user.setPoint(user.getPoint()+1);
				break;
			case -1:
				System.out.println("你输了");
				pc.setPoint(pc.getPoint()+1);
				break;
			default:
				break;
			}
			playTimes++;
			System.out.println("是否继续（y/n）:");
			// 不继续
			if (!scanner.next().toLowerCase().equals("y"))
			{
				break;
			}
		}
		showResult();

	}

	/**
	 * 输出结果
	 */
	public void showResult()
	{
		// TODO Auto-generated method stub
		System.out.println("---------------------------------------");
		System.out.println(user.getName() + "   VS   " + pc.getName());
		System.out.println("对战次数：" + playTimes);
		System.out.println(user.getName() + "得分：" + user.getPoint());
		System.out.println(pc.getName() + "得分：" + pc.getPoint());
		if (user.getPoint() > pc.getPoint())
		{
			System.out.println("你太棒了！");
		} else
		{
			System.out.println("继续努力吧！");
		}

	}
}
